/**
 * 
 */
package com.pkdl.tables;

import java.awt.Color;
import java.awt.Font;
import java.util.Collections;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 * @author Administrator
 * 
 */
public abstract class TableBase {
	public Vector<String> arrCol = new Vector<String>();
	// mang chua du lieu cac dong
	public Vector<Object> arrRow;
	// mang luu giu ten cac cot
	public String[] columnNames;
	public int PREFERRED_SIZE = 12;
	public Color whiteSmoke = new Color(245, 245, 245);
	public Font font = new Font("Microsoft Sans Serif", 0, 11);

	public TableBase() {
	}

	public void editTable(JTable table1) {
		TableColumn column = null;
		// dieu chinh kich NguoiDung, do rong cac cot
		for (int i = 0; i < 4; i++) {
			column = table1.getColumnModel().getColumn(i);
			switch (i) {
			case 0:// icon
				column.setMaxWidth(20);
				break;
			case 1:// ma NguoiDung
				column.setPreferredWidth((int) table1.getPreferredSize()
						.getWidth() / 3 - 20);
				break;
			case 2:// ten NguoiDung
				column.setPreferredWidth((int) table1.getPreferredSize()
						.getWidth() / 3);
				break;
			case 3:// phi dich vu
				column.setPreferredWidth((int) table1.getPreferredSize()
						.getWidth() / 3);
				break;
			}
			if (i == 0) {
				column.setCellRenderer(new MyImageCellRenderer());
			}
		}
		// tuy chinh font, ung voi cac item trong table (in dam)
		Font font = this.font;
		table1.setFont(font);
		table1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		table1.setSelectionBackground(Color.WHITE);
	}

	public abstract void loadDataIntoTable(JTable table);

	public void sortAllRowByFullName(DefaultTableModel model, int colIndex,
			boolean ascending) {
		Vector data = model.getDataVector();
		Collections.sort(data, new ColumnSorterByName(colIndex, ascending));
		model.fireTableStructureChanged();
	}
}
